package com.newlink.building.userinfo.adapter

import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.newlink.building.common_base.model.bean.FamilyManagementListData1
import com.newlink.building.userinfo.R

/**
 * @author wangyang
 * @date 2022/9/16
 * @description 我的——家庭管理页面的Adapter
 */
class Module_UserInfo_FamilyManagementAdapter(data: MutableList<FamilyManagementListData1>) :
    BaseQuickAdapter<FamilyManagementListData1, BaseViewHolder>(
        R.layout.item_family_management,
        data
    ), LoadMoreModule {

    override fun convert(holder: BaseViewHolder, item: FamilyManagementListData1) {
//        Glide.with(context)
//            .load(item.picture)
//            .placeholder(R.mipmap.family_management_head)
//            .transform(MultiTransformation(CenterCrop(), CircleCrop()))
//            .into(holder.getView(R.id.iv_head))
        holder.setText(R.id.tv_name, item.name)
        val num = if (item.aid.toString().trim() == "0" && item.appStatus == 1) {
            ""
        } else {
            item.aid.toString()
        }

        holder.setText(R.id.tv_number, num)

        when (item.appStatus) {
            1 -> {
                //等待激活
                holder.getView<TextView>(R.id.tv_state).visibility = View.VISIBLE
                holder.getView<ImageView>(R.id.iv_call).visibility = View.GONE
                holder.getView<LinearLayout>(R.id.ll_shade).visibility = View.GONE
                holder.setText(
                    R.id.tv_state,
                    context.resources.getString(R.string.family_management_state_wait_activation)
                )
                holder.setTextColor(R.id.tv_state, context.getColor(R.color.default_red))
            }

            2 -> {
                //已激活
                holder.getView<TextView>(R.id.tv_state).visibility = View.GONE
                holder.getView<ImageView>(R.id.iv_call).visibility = View.GONE
                holder.getView<LinearLayout>(R.id.ll_shade).visibility = View.GONE
                holder.setTextColor(R.id.tv_state, context.getColor(R.color.default_text))
            }

            else -> {
                holder.getView<TextView>(R.id.tv_state).visibility = View.VISIBLE
                holder.getView<ImageView>(R.id.iv_call).visibility = View.GONE
                holder.getView<LinearLayout>(R.id.ll_shade).visibility = View.VISIBLE
                holder.setText(
                    R.id.tv_state,
                    context.resources.getString(R.string.family_management_state_unknow)
                )
                holder.setTextColor(R.id.tv_state, context.getColor(R.color.default_yellow))
            }
        }
    }
}